// components/common/indexContent/indexContent.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    articlesList:[]
  },

  lifetimes: {
    attached: function(){
      this.getArticles(0)
    }
  },

  /**
   * 组件的方法列表
   */
  methods: {

    clickDel(e){
      console.log(e)
      wx.showModal({
        title: '警告',
        content: '确认删除本条动态？',
        success (res) {
          if (res.confirm) {
            wx.showLoading({
              title: '数据删除中...',
              mask:true
            })
            wx.cloud.callFunction({
              name:"myArticleDel",
              data:{
                id:e.currentTarget.dataset.id
              }
            }).then(res=>{
              wx.hideLoading();
               wx.showToast({
              title: '删除成功',
              mask:true
            })
             setTimeout(()=>{
              wx.redirectTo({
                    url: '/pages/user/user',
                  })
             },1500)
            })
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
    },


    clickImg(e){
      console.log(e)
      var picarr = e.currentTarget.dataset.picArr
      wx.previewImage({
        urls:picarr
      })
    },

    getArticles(page){
      if(!page) {
        page = this.data.articlesList.length
      }
      // else{
      //   this.setData({
      //     articlesList:[]
      //   })
      // }
      wx.cloud.callFunction({
        name:"myArticleGetAll",
        data:{
          page:page
        }
      }).then(
        res=>{
          console.log(res);
          // console.log(this.data.articlesList.length)
          var oldList = this.data.articlesList;
          var newList = oldList.concat(res.result.data)
          this.setData({
            articlesList:newList
          })
          wx.stopPullDownRefresh()
        }
      )
    }
  }
})